//var thisid=location.href.match(/(thisid=)([0-9a-zA-Z]+)/).splice("=")[2];
if(/isstrange/.test(location.href)){
    $("#loading").remove();
}
var thisid;
if($.cookie("otherid")){
    thisid=$.cookie("otherid");
}else{
    thisid=id;
}
var whoname="";
//页面返回------------------------------------------------
$(".mweb_modal_back_button").click(function(){
    history.go(-1);
});
//经验金钱判断能否进入------------------------------------
function moneytest(e){
    //判断能不能去看详情页
    var euserid= e.dataset.euser;
    var thiseid= e.dataset.eid;
    var score=e.dataset.score;
    $.ajax({
        type:"post",
        datatype:"json",
        url:textexpurl,
        data:{"quserId":euserid,"contentId":thiseid,"userId":id,"score":score},
        success:function(d){
            console.log(d);
            if(d.Message=="自己的经验"||d.Message=="已付费"||d.Message=="未付费"){
                $.cookie("paynum",thiseid);
                location.href='shareexppage.html?eid='+thiseid;
            }else{
                $("body").css("overflow","hidden");
                $(".moneyinfomob").css("display","block");
            }
        }
    });
}
//去充值
$("#okgobtn").click(function(){
    location.href="scoredetial.html";
});
//取消
$("#cancel").click(function(){
    $("body").css("overflow","auto");
    $(".moneyinfomob").css("display","none");
});
//加载最新动态方法------------------------------------------
var currentIndex=1;//分页
var pageSize=10;//个数
function aj(currentIndex,pageSize){
    //var thisid=location.href.match(/(thisid=)([0-9a-zA-Z]+)/).splice("=")[2];
    $.ajax({
        type:"get",
        datatype:"json",
        url:"http://42.62.66.198:9001/api/PuluUser/GetUserStatusByUserId?userId="+thisid+"&currentIndex="+currentIndex+"&pageSize="+pageSize,
        success:function(d){
            var data= d.Data;
            console.log("获取的最新动态数据",data);
            if(data&&data.length>0){
                if(data.length<pageSize){
                    $("#loading").remove();
                }
                for(var i=0;i<data.length;i++){
                    //时间--------------------
                    var dataarr=data[i].time.split("-");
                    var monthnum=dataarr[1];//月
                    //console.log(dataarr);
                    var daynum=dataarr[2].match(/^[0-9]+/)[0];//日
                    //是否有评论--------------
                    var statusword="";
                    if(data[i].des||data[i].answerContent){
                        var word=data[i].des||data[i].answerContent;
                        var newword=codetoface(word);
                        statusword="<div class='status'>"+newword+"</div>";
                    }
                    //是否有钱----------------
                    var score="";
                    if(data[i].score){
                        score="<span style='color:#f4c600;padding-left:5px;'><img src='../img/money04.png' style='width:12px;height:13px;margin-top:-3px;'>"+parseFloat(data[i].score)/100+"</span>"
                    }
                    //新闻--------------------
                    if(data[i].contenttypeName=="新闻"){
                        $("#mainbodyplace").append("<div class='listbox'><div class='leftplace'><div class='day'>"+daynum+"</div><div class='month'>"+monthnum+"</div> <div class='monthword'>月</div></div><div class='rightplace'><div class='rightplacebox'><div class='title'><span class='who'>"+whoname+"</span><span class='how'>"+data[i].operatetypeName+"</span>了此<span class='what'>新闻</span></div>"+statusword+"<div class='info'><a href='"+data[i].url+"'>"+data[i].content+"</a></div></div></div></div>");
                    }
                    //问题---------------------
                    else if(data[i].contenttypeName=="问题"){
                        $("#mainbodyplace").append("<div class='listbox'><div class='leftplace'> <div class='day'>"+daynum+"</div> <div class='month'>"+monthnum+"</div> <div class='monthword'>月</div></div><div class='rightplace'> <div class='rightplacebox'> <div class='title'> <span class='who'>"+whoname+"</span><span class='how'>"+data[i].operatetypeName+"</span>了此<span class='what'>问题</span>"+score+"</div>"+statusword+"<div class='info'><a href='questiondetail.html?qid="+data[i].contentid+"'>"+data[i].content+"</a></div></div></div></div>");              //评论
                    }
                    //经验------------------------
                    else if(data[i].contenttypeName=="经验"){
                        $("#mainbodyplace").append("<div class='listbox'><div class='leftplace'> <div class='day'>"+daynum+"</div> <div class='month'>"+monthnum+"</div> <div class='monthword'>月</div></div><div class='rightplace'> <div class='rightplacebox'> <div class='title'> <span class='who'>"+whoname+"</span><span class='how'>"+data[i].operatetypeName+"</span>了此<span class='what'>经验</span>"+score+"</div>"+statusword+"<div class='info'><a data-score='"+data[i].score+"' data-eid='"+data[i].contentid+"' data-euser='"+data[i].userId+"' onclick='moneytest(this)'>"+data[i].content+"</a></div></div></div></div>");
                        //经验金额               经验ID                               经验发布者
                    }
                }
            }
            else{
                $("#loading").remove();
            }
        }
    })
}
$().ready(function(){
    //var thisid=location.href.match(/(thisid=)([0-9a-zA-Z]+)/).splice("=")[2];
    var id= $.cookie("MYID");
    console.log("id",id);
    if(thisid==id){
        whoname="您";
        aj(currentIndex,pageSize);
    }else{
        $.ajax({
            type: "post",
            url: "http://42.62.66.198:9001/api/puluuser/getuser",
            data: { "userId": thisid },
            datatype: "json",//"xml", "html", "script", "json", "jsonp", "text".
            success:function(d){
                whoname= d.Data.nick;
                //获取用户信息及最新动态-----------------------------------
                aj(currentIndex,pageSize);
            }
        });
    }
});
//页面滚动加载-------------------------------------------------
$(window).scroll(function(){
    if(!/isstrange/.test(location.href)){
        var mainheight=$("#page_wrapper").height();
        var windowheight=$(window).height();
        var chajuli=$("#page_wrapper").offset().top - $(window).scrollTop();
        var scrollheight=$(window).scrollTop();
        var cz=windowheight-mainheight+5;
        if(chajuli<cz){
            currentIndex++;
            aj(currentIndex,pageSize);
        }
    }
});